package com.tmpt.utils;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

public class JsonMap {

	
	public static Map<String,String[]> json2Map(String json){
		Map<String,String[]> paramMap1 = new HashMap<String, String[]>();
		JSONObject jo = JSONObject.fromObject(json);
		Iterator it = jo.keys();
		while(it.hasNext()){
			String key = (String)it.next();
			JSONArray jo1 = jo.optJSONArray(key);
			String[] ss = new String[jo1.size()];
			for(int i=0;i<jo1.size();i++){
				ss[i] = jo1.optString(i);
			}
			paramMap1.put(key, ss);
		}
		return paramMap1;
	}

	public static Map<String,Object> json2Map1(String json){
		Map<String,Object> paramMap1 = new HashMap<String, Object>();
		JSONObject jo = JSONObject.fromObject(json);
		Iterator it = jo.keys();
		while(it.hasNext()){
			String key = (String)it.next();
			JSONArray jo1 = jo.optJSONArray(key);
			/*
			String[] ss = new String[jo1.size()];
			for(int i=0;i<jo1.size();i++){
				ss[i] = jo1.optString(i);
			}*/
			paramMap1.put(key, jo1.optString(0));
		}
		return paramMap1;
	}
	
	public static String map2Json(Map<String,String[]> paramMap){
		String json = JSONObject.fromObject(paramMap).toString();
		return json;
	}
}
